﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App1
{
    class Rook: Pieces
    {
        public override bool CheckLegalMove(int row, int col)
        {
            bool legal = false;
            int count = 0;
            int t = -1;
            int n = 0;
            if (row == _row)
            {
                if (_col < col)
                {
                    t = _col;
                    n = col;
                }
                else
                {
                    t = col;
                    n = _col;
                }
                for (int i = t + 1; i < n; ++i)
                    if (Board.Square[_row, i].State)
                        ++count;
                if(count == 0)
                    if(!Board.Square[row, col].State)
                        legal = true;
                    else
                        if(Board.Square[row, col].Side != _side)
                            legal = true;
            }
            if (col == _col)
            {
                if (_row < row)
                {
                    t = _row;
                    n = row;
                }
                else
                {
                    t = row;
                    n = _row;
                }
                for (int i = t + 1; i < n; ++i)
                    if (Board.Square[i, _col].State)
                        ++count;
                if (count == 0)
                    if (!Board.Square[row, col].State)
                        legal = true;
                    else
                        if (Board.Square[row, col].Side != _side)
                            legal = true;
            }
            return legal;
        }

        public override bool CheckSafeOfKing(int row, int col)
        {
            return true;
        }
    }
}
